package com.mofang.powerdekorhelper.activity.product;

import android.view.View;
import android.view.ViewGroup;

import com.mofang.powerdekorhelper.R;
import com.mofang.powerdekorhelper.adapter.ProductListAdapter;
import com.mofang.powerdekorhelper.base.MvpActivity;
import com.mofang.powerdekorhelper.base.recycleview.BaseRecycleViewAdapter;
import com.mofang.powerdekorhelper.base.recycleview.BaseRecycleViewGrid;
import com.mofang.powerdekorhelper.model.Product;
import com.mofang.powerdekorhelper.persenter.ProductListPersenter;
import com.mofang.powerdekorhelper.utils.LoadPrograss;
import com.mofang.powerdekorhelper.utils.T;
import com.mofang.powerdekorhelper.view.ProductListView;
import com.mofang.powerdekorhelper.witget.TitleBar;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by luofei on 2017/8/24 0024.
 */

public class ProductListActivity extends MvpActivity<ProductListView, ProductListPersenter> implements ProductListView {

    @BindView(R.id.product_list_title)
    TitleBar mTitleBar;

    @BindView(R.id.product_list_grid)
    BaseRecycleViewGrid productRecycle;

    ProductListAdapter adapter;

    LoadPrograss loadPrograss;

    @Override
    public void initView() {
        inflateLayout(R.layout.activity_product_list_layout);
        initTitleBarWithback(mTitleBar, R.string.product_detail);
        productRecycle.setColumNum(2, false);
        loadPrograss = new LoadPrograss(this);
    }

    @Override
    public void initData() {
        presenter.getProductList("");
    }

    @OnClick(R.id.product_list_classify)
    void onclick(View view) {
        switch (view.getId()) {

            case R.id.product_list_classify:

                toActivity(ProductListActivity.this, ProductDetailActivity.class);
                break;
        }
    }

    @Override
    public void setProductList(Product productList) {

        adapter = new ProductListAdapter(productList.getResult().getData(), this, R.layout.product_list_item_layout);
        adapter.setOnItemClickListner(new BaseRecycleViewAdapter.OnItemClickListner() {
            @Override
            public void onItemClickListner(ViewGroup parent, View v, int position) {
                toActivity(ProductListActivity.this, ProductDetailActivity.class);
            }
        });
        productRecycle.setAdapter(adapter);
        hideProgress();
    }

    @Override
    public void showProgress() {
        loadPrograss.show();
    }

    @Override
    public void hideProgress() {
        loadPrograss.hide();
    }

    @Override
    public void toast(CharSequence s) {
        T.showShort(this, s);
    }

    @Override
    public void toast(int id) {

    }

    @Override
    public void showNullLayout() {

    }

    @Override
    public void hideNullLayout() {

    }

    @Override
    public void showErrorLayout(View.OnClickListener listener) {

    }

    @Override
    public void hideErrorLayout() {

    }

    @Override
    public void onError(String errorInfo) {
        toast(errorInfo);
        loadPrograss.hide();
    }

    @Override
    public ProductListPersenter initPresenter() {
        return new ProductListPersenter();
    }

}
